import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
from functools import wraps
import cmath
import warnings
import sys
import jieba
import wordcloud
import re

def re_findall(content,re_rule):
    pattern = re.compile(re_rule)  # 构建patten
    get = pattern.findall(content) #用re进行查找
    return get

#两个字符串中的内容相减str1-str2
def subtraction(str1, str2):
    set_str1 = set(list(str1))
    set_str2 = set(list(str2))
    set_str3 = set_str1 - set_str2
    str_subtraction = ''.join(list(set_str3))  # 将list转为str
    return str_subtraction

#将字符换进行乱序处理
def suffle(str):
    list_str_shuffle = list(set(list(str)))
    str_shuffle = ''.join(list_str_shuffle)
    return str_shuffle

#将txt拆分成等分的几部分,save_name只要写开头就行，不用加后缀
def txt_cut(path,num,save_name):
    open_txt(path, encoding='ANSI')
    content = open_txt(path, encoding='ANSI')  # 打开txt文件
    content_list = content.split('\n')  # 按回车把内容进行分割做成列表
    len_all = len(content_list)
    len_part = len_all//num
    for i in range(num):#range，包含左不包含右
        if i != num-1:
            content_part = content_list[i*len_part:(i+1)*len_part]#list索引提取，包含左不包含右
        else:content_part = content_list[i*len_part:]
        file_name = save_name+'part'+str(i+1)+'.txt'
        file = open(file_name, "w")
        for word in content_part:
                word_save = word + '\n'
                file.write(word_save)
        file.close()

#统计字符串中中有哪些字
def zi_list(content):
    zi_list = []
    for i in content:
        if '\u4e00' <= i <= '\u9fff':
            zi_list.append(i)
    zi_list = list(set(zi_list))
    return zi_list


